package com.dgut.forum.controller;

import com.dgut.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

/*
* author:XueWQ
* */
//表示返回的结果是数据
@Api(tags="测试接口")
@RestController
//配置一级访问路径
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试方法1,打印hello，spring boot")
    @GetMapping("/hello")
    public String Hello(){
       return "hello，spring boot";
    }
    @ApiOperation("测试方法2,测试排除exception异常")
    @GetMapping("/exception")
    public String testException() throws Exception {
        throw new Exception("这是一个Exception异常");
    }
    @ApiOperation("测试方法3,测试抛出自定义ApplicationException异常")
    @GetMapping("/ApplicationException")
    public String testApplicationException()  {
        throw new ApplicationException("这是一个ApplicationException异常");
    }
    @PostMapping("/helloByName")
    @ApiOperation("测试接口4.根据名字说hello")
    public String helloByName(@ApiParam(value="姓名") @RequestParam("name") String name){
        return name+",hello";
    }
}
